﻿using Domain.Entities.Tenants;

namespace Domain.Entities
{
    /// <summary>
    /// 角色
    /// </summary>
    public class Role : BaseAuditableEntity, IAuditTrial, ITenant
    {
        public Role()
        {
            UserRoles = new HashSet<UserRole>();
            RoleMenus = new HashSet<RoleMenu>();
        }
        public Role(string roleName,string description)
        {
            RoleName = roleName;
            Description = description;
        }

        /// <summary>
        /// 角色名称
        /// </summary>
        public virtual string RoleName { get; set; }

        /// <summary>
        /// 角色编码
        /// </summary>
        public virtual string RoleCode { get; set; }

        /// <summary>
        /// 是否激活
        /// </summary>
        public virtual bool IsActive { get; set; }

        /// <summary>
        /// 排序
        /// </summary>
        public virtual int Sort { get; set; }

        /// <summary>
        /// 角色描述
        /// </summary>
        public virtual string Description { get; set; } 

        public virtual ICollection<UserRole> UserRoles { get; set; }
        public virtual ICollection<RoleMenu> RoleMenus { get;}

        /// <summary>
        /// 是否激活
        /// </summary>
        public void IsActived(bool? isActive = null)
        {
            if (isActive.HasValue)
            {
                IsActive = isActive.Value;
            }
            else
            {
                IsActive = !IsActive;
            }
        }
        public virtual Tenant? Tenant { get; set; }
        public virtual string? TenantId { get; set; } = null;
    }
}
